import { contextBridge, ipcRenderer } from 'electron'
import { electronAPI } from '@electron-toolkit/preload'
// Custom APIs for renderer
const api = {
  // 获取视频源
  getVideoSources: () => ipcRenderer.invoke('get-video-sources'),
  // 获取当前窗口信息
  getCurrentWindowInfo: () => ipcRenderer.invoke('get-current-window-info'),
  // 录制控制
  startRecording: (options) => ipcRenderer.invoke('start-recording', options),
  stopRecording: () => ipcRenderer.invoke('stop-recording'),
  // 发送录制数据
  sendRecordingData: (data) => ipcRenderer.send('recording-data', data),
  // 事件监听
  onRecordingProgress: (callback) => ipcRenderer.on('recording-progress', callback),
  onRecordingError: (callback) => ipcRenderer.on('recording-error', callback),
  removeAllListeners: (channel) => ipcRenderer.removeAllListeners(channel)
}
if (process.contextIsolated) {
  try {
    contextBridge.exposeInMainWorld('electron', electronAPI)
    contextBridge.exposeInMainWorld('api', api)
  } catch (error) {
    console.error(error)
  }
} else {
  window.electron = electronAPI
  window.api = api
}
